package com.lanou.userLogin.cart.web.servlet;

import com.lanou.userLogin.cart.domin.CartItem;
import com.lanou.userLogin.cart.service.CartService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/cartDeleteAllServlet")
public class CartDeleteAllServlet extends HttpServlet {

    private CartService cs = new CartService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        List<CartItem> cartList = (List<CartItem>) session.getAttribute("cartItemList");
        List<CartItem> itemList = cs.cartDeleteAll(cartList);
        session.setAttribute("cartList", itemList);
        req.getRequestDispatcher("/jsps/cart/list.jsp").forward(req, resp);
    }
}
